// 筛选输入框混入
export const inputSearch = {
	methods: {
		input(value) {
			let key = value
			let list = this.deliverplan;
			for (let item of list) {
				let a = key;
				let view = this.searchView
				let c = item[view]
				if (c.search(a) != -1) {
					item.isShow = true
				} else {
					item.isShow = false
				}
			}
			this.deliverplan = list
		},
		remove() {
			if (this.message) {
				this.$refs.screen.modalName = 'DrawerModalR'
			} else {
				let list = this.deliverplan;
				for (let item of list) {
					item.isShow = true
				}
				this.deliverplan = list
			}
		},
		clean() {
			let list = this.deliverplan;
			for (let item of list) {
				item.isShow = true
			}
			this.deliverplan = list
		}
	},
}
// 图表数据混入
export const ucharts = {
	onLoad() {
		//#ifdef MP-ALIPAY
		uni.getSystemInfo({
			success: function(res) {
				if (res.pixelRatio > 1) {
					//正常这里给2就行，如果pixelRatio=3性能会降低一点
					//this.pixelRatio =res.pixelRatio;
					this.pixelRatio = 2;
				}
			}
		});
		//#endif
		this.cWidth = uni.upx2px(750);
		this.cHeight = uni.upx2px(500);
		// this.cWidth2 = uni.upx2px(700);
		// this.cHeight2 = uni.upx2px(1100);
		this.cWidth2 = this.screenWidth - uni.upx2px(120);
		this.cHeight2 = this.screenHeight - uni.upx2px(this.CustomBar + 115);
		this.getServerData();
	},
}

// 列表上拉下拉刷新混入
export const scrollrefresh = {
	data() {
		return {
			tabBars: [],
			scrollTop: 0,
			infoindex: 2,
			old: {
				scrollTop: 0
			},
		}
	},
	async onLoad() {
		// this.loadTabbars();
	},
	methods: {
		//获取分类
		loadTabbars() {
			let tabList = this.deliverplan;
			tabList.forEach(item => {
				item.newsList = [];
				item.refreshing = 0;
			})
			this.tabBars = tabList;
			this.loadNewsList('add')
		},
		//新闻列表
		loadNewsList(type) {
			let tabItem = this.tabBars;
			// type add 加载更多 refresh下拉刷新
			if (type === 'add') {
				if (this.infoindex === 2) {
					return;
				}
				this.infoindex = 1
			}
			// #ifdef APP-PLUS
			else if (type === 'refresh') {
				tabItem.refreshing = true;
			}
			// #endif

			//setTimeout模拟异步请求数据
			setTimeout(() => {
				//下拉刷新 关闭刷新动画
				if (type === 'refresh') {
					this.$refs.mixPulldownRefresh && this.$refs.mixPulldownRefresh.endPulldownRefresh();
					// #ifdef APP-PLUS
					tabItem.refreshing = false;
					// #endif
					this.deliverplan = this.deliverplan.slice(0, 11)
					if (this.deliverplan.length < 10) {
						this.infoindex = 2
					} else {
						this.infoindex = this.deliverplan.length > 22 ? 2 : 0;
					}
				}
				//上滑加载 处理状态
				if (type === 'add') {
					this.deliverplan = this.deliverplan.concat(this.deliverplan);
					if (this.deliverplan.length < 6) {
						this.infoindex = 2
					} else {
						this.infoindex = this.deliverplan.length > 22 ? 2 : 0;
					}
					// setTimeout(() => {
					//     const className = '.FirstList';
					//     const query = uni.createSelectorQuery().in(this);
					//     query.select(className).boundingClientRect((res) => {
					//         if (res) {
					//             console.log(res.height);
					//             if (res.height < this.screenHeight) {
					//                 this.infoindex = 2
					//             } else {
					//                 this.infoindex = this.deliverplan.length > 22 ? 2 : 0;
					//             }
					//         }
					//     }).exec()
					// }, 1000)
				}
			}, 600)
		},
		//设置scroll-view是否允许滚动，在小程序里下拉刷新时避免列表可以滑动
		setEnableScroll(enable) {
			if (this.enableScroll !== enable) {
				this.enableScroll = enable;
			}
		},
		//下拉刷新
		onPulldownReresh() {
			this.loadNewsList('refresh');
		},
		//上滑加载
		loadMore() {
			this.loadNewsList('add');
		},
		scroll(e) {
			this.isShow = e.detail.scrollTop > 600 ? true : false
			this.old.scrollTop = e.detail.scrollTop
		},
		topClick() {
			this.scrollTop = this.old.scrollTop
			this.$nextTick(function() {
				this.scrollTop = 0
			});
		}
	}

}
export const viewTable = {
	data() {
		return {
			// ===================访客记录数据===========================
			deliverplantwo: [],
			finaleColumnstwo: [
				// {
				// 	title: '<span style="color: #333"><span style="display: inline-block; width: 10px; height: 10px; line-height: 10px; margin-right: 5px; border: solid 1px #000; border-radius: 50%; font-size: 11px; text-align: center; vertical-align: middle;">!</span><span st yle="vertical-align: middle;">姓名</span></span>',
				// 	format: {
				// 		template: "<span><span style='vertical-align: middle;'>#LUSERCODE#</span>",
				// 		names: ["LUSERCODE"]
				// 	},
				// 	width: 180
				// },
				{
					title: "访问时间",
					key: "LATEDATE",
					width: 300,
					isShow: true
					// listenerClick: true
				},
				{
					title: "访问地点",
					key: "LATEPLACE",
					isShow: true,
					// sort: true,
					width: 260
				},
				{
					title: "识别机器",
					key: "LATEMACHINE",
					isShow: true,
					width: 260
				},
				{
					title: "授权开始访问时间",
					key: "LALLOWBEGINDATE",
					isShow: true,
					width: 260
				},
				{
					title: "授权结束访问时间",
					key: "LALLOWENDDATE",
					isShow: true,
					width: 260
				},
				{
					title: "授权人",
					key: "LREMARK",
					isShow: true,
					width: 260
				}
			],

			// ===================访客记录数据===========================
			deliverplanthree: [],
			finaleColumnsthree: [
				// {
				// 	title: '<span style="color: #333"><span style="display: inline-block; width: 10px; height: 10px; line-height: 10px; margin-right: 5px; border: solid 1px #000; border-radius: 50%; font-size: 11px; text-align: center; vertical-align: middle;">!</span><span st yle="vertical-align: middle;">姓名</span></span>',
				// 	format: {
				// 		template: "<span><span style='vertical-align: middle;'>#LUSERCODE#</span>",
				// 		names: ["LUSERCODE"]
				// 	},
				// 	width: 180
				// },
				{
					title: "访问时间",
					key: "LATEDATE",
					isShow: true,
					width: 260,
					// listenerClick: true
				},
				{
					title: "访问地点",
					key: "LATEPLACE",
					isShow: true,
					// sort: true,
					width: 260
				},
				{
					title: "识别机器",
					key: "LATEMACHINE",
					isShow: true,
					width: 260
				},
				// {
				// 	title: "识别图片",
				// 	key: "LREMARK",
				// 	width: 260
				// }
			],
			// ===================告警记录数据===========================


			// ===================考勤详情数据=======================
			deliverplanfour: [],
			finaleColumnsfour: [{
					title: '<span style="color: #333"><span style="display: inline-block; width: 10px; height: 10px; line-height: 10px; margin-right: 5px; border: solid 1px #000; border-radius: 50%; font-size: 11px; text-align: center; vertical-align: middle;">!</span><span st yle="vertical-align: middle;">姓名</span></span>',
					format: {
						template: "<span><span style='vertical-align: middle;'>#LUSERNAME#</span>",
						names: ["LUSERNAME"]
					},
					width: 180,
					isShow: true
				},
				{
					title: "员工号",
					key: "LUSERCODE",
					isShow: true,
					width: 200,
					// listenerClick: true
				},

				{
					title: "考勤时间",
					key: "LATEDATE",
					isShow: true,
					width: 260
				},
				{
					title: "考勤地点",
					key: "LATEPLACE",
					isShow: true,
					width: 260
				},
				{
					title: "考勤机器",
					key: "LATEMACHINE",
					isShow: true,
					width: 260
				},

			],

			// ===================考勤详情数据=======================

			// ===================络筒实时数据=======================
			deliverplanWinding: [],
			finaleColumnsWinding: [{
					title: "机器号",
					key: "LUSERCODE",
					width: 150,
					isShow: true
					// listenerClick: true
				},
				{
					title: "机器状态",
					key: "LATETYPE",
					isShow: true,
					// sort: true,
					width: 300
				},
				{
					title: "机器类型",
					key: "LPHOTO",
					isShow: true,
					width: 300
				},
			],
			// ===================络筒实时数据=======================

			// ===================测试数据===========================
			deliverplan: [{
					name: "张三",
					age: 10,
					gender: "男",
					address: "安徽",
					isShow: true
				},
				{
					name: "赵四",
					age: 16,
					gender: "女",
					address: "安徽",
					isShow: true
				},
				{
					name: "王五",
					age: 78,
					gender: "男",
					address: "安徽",
					isShow: true
				},
				{
					name: "李六",
					age: 45,
					gender: "女",
					address: "安徽",
					isShow: true
				}
			],
			finaleColumns: [{
					title: '<span style="color: #333"><span style="display: inline-block; width: 10px; height: 10px; line-height: 10px; margin-right: 5px; border: solid 1px #000; border-radius: 50%; font-size: 11px; text-align: center; vertical-align: middle;">!</span><span st yle="vertical-align: middle;">姓名</span></span>',
					format: {
						template: "<span><span style='vertical-align: middle;'>#name#</span>",
						names: ["name"]
					},
					width: 180,
					isShow: true
				},
				{
					title: "年龄",
					key: "age",
					width: 260,
					sort: true,
					listenerClick: true,
					isShow: true
				},
				{
					title: "性别",
					key: "gender",
					width: 260,
					isShow: true
				},
				{
					title: "地址",
					key: "address",
					width: 260,
					isShow: true
				},
			],
			// ===================测试数据===========================


			// ===================细沙报表数据===========================
			deliverplanfive: [{
					code: "001",
					name: "张三",
					age: '一班',
					chejian: '一车间',
					taihao: "台号一",
					gender: "男",
					address: "安徽",
					isShow: true
				},
				{
					name: "赵四",
					code: "002",
					age: '一班',
					chejian: '一车间',
					taihao: "台号一",
					gender: "女",
					address: "安徽",
					isShow: true
				},
				{
					name: "赵四",
					code: "003",
					age: '一班',
					taihao: "台号一",
					chejian: '一车间',
					gender: "女",
					address: "安徽",
					isShow: true
				},
				{
					name: "王五",
					code: "004",
					age: '一班',
					chejian: '一车间',
					taihao: "台号一",
					gender: "男",
					address: "安徽",
					isShow: true
				},
				{
					name: "李六",
					code: "005",
					age: '一班',
					chejian: '一车间',
					taihao: "台号一",
					gender: "女",
					address: "安徽",
					isShow: true
				}
			],
			finaleColumnsfive: [{
					title: "员工号",
					key: "code",
					width: 150,
					isShow: true
				},
				{
					title: "姓名",
					key: "name",
					width: 150,
					isShow: true
				},
				{
					title: "车间",
					key: "chejian",
					width: 150,
					isShow: true
				},
				{
					title: "台号",
					key: "taihao",
					width: 150,
					isShow: true
				},
				{
					title: "班组",
					key: "age",
					width: 150,
					isShow: true
				},

				{
					title: "班次",
					key: "address",
					width: 150,
					isShow: true
				},
				{
					title: "重量(千克)",
					key: "name",
					width: 200,
					isShow: true
				},
				{
					title: "落纱次数",
					key: "age",
					width: 200,
					isShow: true
				},
				{
					title: "落停(分钟)",
					key: "gender",
					width: 200,
					isShow: true
				},
				{
					title: "品种",
					key: "address",
					width: 150,
					isShow: true
				},
				{
					title: "平均接头(分钟)",
					key: "name",
					width: 200,
					isShow: true
				},
				{
					title: "千锭时断头",
					key: "age",
					width: 200,
					isShow: true
				},
				{
					title: "实际效率(%)",
					key: "gender",
					width: 200,
					isShow: true
				},
				{
					title: "生产效率(%)",
					key: "address",
					width: 200,
					isShow: true
				},
			],

			// ===================运转报表数据===========================
			deliverplanwork: [{
					code: "2020-06-29",
					name: "2020-06-29",
					age: '一班',
					chejian: '8小时',
					taihao: "台号一",
					gender: "男",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "2020-06-29",
					code: "2020-06-29",
					age: '一班',
					chejian: '8小时',
					taihao: "台号一",
					gender: "女",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "2020-06-29",
					code: "2020-06-29",
					age: '一班',
					taihao: "台号一",
					chejian: '8小时',
					gender: "女",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "2020-06-29",
					code: "2020-06-29",
					age: '一班',
					chejian: '8小时',
					taihao: "台号一",
					gender: "男",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "2020-06-29",
					code: "2020-06-29",
					age: '一班',
					chejian: '8小时',
					taihao: "台号一",
					myname:'张远涛',
					gender: "女",
					address: "安徽",
					isShow: true
				}
			],
			finaleColumnswork: [{
					title: "开始时间",
					key: "code",
					width: 150,
					isShow: true
				},
				{
					title: "结束时间",
					key: "name",
					width: 150,
					isShow: true
				},
				{
					title: "完成工作量",
					key: "chejian",
					width: 150,
					isShow: true
				},
				{
					title: "主要工作",
					key: "taihao",
					width: 150,
					isShow: true
				},
				{
					title: "施工工号",
					key: "age",
					width: 150,
					isShow: true
				},

				{
					title: "添加燃油",
					key: "address",
					width: 150,
					isShow: true
				},
				{
					title: "签认人",
					key: "myname",
					width: 200,
					isShow: true
				}
			],
			// ===================运转报表数据===========================

			// ===================产能分析报表数据===========================
			deliverplancapacity: [{
					code: "2",
					name: "8",
					age: '8小时',
					chejian: 'A类别',
					taihao: "8小时",
					gender: "男",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "3",
					code: "7",
					age: '8小时',
					chejian: 'A类别',
					taihao: "8小时",
					gender: "女",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "4",
					code: "3",
					age: '8小时',
					taihao: "8小时",
					chejian: 'A类别',
					gender: "女",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "5",
					code: "5",
					age: '8小时',
					chejian: 'A类别',
					taihao: "8小时",
					gender: "男",
					address: "安徽",
					myname:'张远涛',
					isShow: true
				},
				{
					name: "8",
					code: "5",
					age: '8小时',
					chejian: 'A类别',
					taihao: "8小时",
					myname:'张远涛',
					gender: "女",
					address: "安徽",
					isShow: true
				}
			],
			finaleColumnscapacity: [{
					title: "设备数量",
					key: "code",
					width: 150,
					isShow: true
				},
				{
					title: "不良PPM",
					key: "name",
					width: 150,
					isShow: true
				},
				{
					title: "类别统计",
					key: "chejian",
					width: 150,
					isShow: true
				},
				{
					title: "理论公时",
					key: "taihao",
					width: 150,
					isShow: true
				},
				{
					title: "实际公时",
					key: "age",
					width: 150,
					isShow: true
				},
			
				{
					title: "工作效率",
					key: "address",
					width: 150,
					isShow: true
				},
				{
					title: "开工公时",
					key: "myname",
					width: 200,
					isShow: true
				},
				{
					title: "开工率",
					key: "myname",
					width: 200,
					isShow: true
				},
				{
					title: "预计生产量",
					key: "myname",
					width: 200,
					isShow: true
				}
			],
			// ===================产能分析报表数据===========================
			

			// ===================细沙报表数据===========================


			// ===================员工产量报表===========================
			deliverplanyield: [],
			finaleColumnsyield: [{
					title: "员工号",
					key: "LUSERCODE",
					width: 200,
					isShow: false
				},
				{
					title: "员工姓名",
					key: "LUSERNAME",
					width: 200,
					isShow: true
				},
				{
					title: "机器编号",
					key: "LMACHINENO",
					width: 150,
					isShow: true
				},
				{
					title: "工序",
					key: "LPRCTYPE",
					width: 150,
					isShow: true
				},
				{
					title: "生产数量",
					key: "LQTY",
					width: 200,
					isShow: true
				},
				{
					title: "开始时间",
					key: "LBEGINDATE",
					width: 280,
					isShow: true
				},
				{
					title: "上机产量",
					key: "LBEGINWEIGHT",
					width: 200,
					isShow: true
				},
				{
					title: "结束时间",
					key: "LENDDATE",
					width: 280,
					isShow: true
				},
				{
					title: "下机产量",
					key: "LENDWEIGHT",
					width: 200,
					isShow: true
				},
				{
					title: "生产订单号",
					key: "LLOADNO",
					width: 200,
					isShow: true
				},

				{
					title: "工作时间",
					key: "LTIME",
					width: 280,
					isShow: true
				},
				{
					title: "结算时间",
					key: "LTIMESTAMP",
					width: 280,
					isShow: true
				},
				{
					title: "计数方式",
					key: "LUNIT",
					width: 200,
					isShow: true
				},
			],

			deliverplanDoffing: [],
			finaleColumnsDoffing: [{
					title: "员工姓名",
					key: "LUSERNAME",
					width: 200,
					isShow: true
				},
				{
					title: "班次",
					key: "LCLASSINDEX",
					width: 200,
					isShow: true
				},
				{
					title: "车间",
					key: "LPLANT",
					width: 200,
					isShow: true
				},
				{
					title: "机器号",
					key: "LMACHINENO",
					width: 200,
					isShow: true
				},
				{
					title: "总产量",
					key: "LWEIGHT",
					width: 200,
					isShow: true
				},
				{
					title: "货品名称",
					key: "LITEMNAME",
					width: 200,
					isShow: true
				},
				{
					title: "货品编号",
					key: "LITEMCODE",
					width: 200,
					isShow: true
				},
				{
					title: "满纱次数",
					key: "LLSCS",
					width: 200,
					isShow: true
				},
				{
					title: "生产效率",
					key: "LSCXL",
					width: 200,
					isShow: true
				},
				{
					title: "实际效率",
					key: "LSJXL",
					width: 200,
					isShow: true
				},
				{
					title: "总工时",
					key: "LSUMTIME",
					width: 200,
					isShow: true
				}
			]

		}
	},
	onLoad() {
		// 性能测试 15条自定义内容带头像
		for (let i of new Array(15)) {
			this.deliverplan.push({
				name: "王五",
				age: 30,
				gender: "男",
				address: "安徽",
				isShow: true
			})
		}
	},
	methods: {
		doSort(res) {
			if (res.type == 'desc') {
				this.deliverplan.sort(function(a, b) {
					return b['age'] - a['age'] // 降序
				})
			} else {
				this.deliverplan.sort(function(a, b) {
					return a['age'] - b['age'] // 升序
				})
			}
		},
		tableSelect(selectList) {
			this.$emit('tableSelect', selectList)
		}
	}
}
// 常用项混入
export const Commonly = {
	data() {
		return {
			value1: false,
			index: '',
			x: 0,
			y: 0,
			Commonlylist: [],
			data1: [{
				title: '添加为常用项'
			}],
		}
	},
	computed: {
		ip() {
			let ip = uni.getStorageSync('IP') || 'http://47.101.156.202'
			let port = uni.getStorageSync('PORT') || '8443'
			return ip + ':' + port
		},
	},
	methods: {
		zylongtap(e, info) {
			this.Commonlylist = info
			this.y = e.touches[0].clientY
			this.x = e.touches[0].clientX
			if (e.touches[0].clientX < 100) {
				this.x = 100
			}
			// console.log(this.screenHeight - uni.upx2px(190));
			if (e.touches[0].clientY > this.screenHeight - uni.upx2px(210)) {
				this.y = this.screenHeight - uni.upx2px(210)
			}
			this.value1 = true
		},
		homelongtap(e, info, index) {
			this.index = index
			this.Commonlylist = info
			this.y = e.touches[0].clientY
			this.x = e.touches[0].clientX
			if (e.touches[0].clientX < 100) {
				this.x = 100
			}
			// console.log(this.screenHeight - uni.upx2px(190));
			if (e.touches[0].clientY > this.screenHeight - uni.upx2px(210)) {
				this.y = this.screenHeight - uni.upx2px(210)
			}
			this.value1 = true
		},
		zyinput() {
			this.value1 = !this.value1
			this.x = 0
			this.y = 0
		},
		hometapPopup() {
			uni.request({
				url: this.ip + '/api/deleteUserStaple', //仅为示例，并非真实接口地址。
				header: {
					'token': uni.getStorageSync('token')
				},
				data: {
					lid: this.Commonlylist.lid
				},
				success: (res) => {
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						global.Commonly = true
						this.Commonly.splice(this.index, 1)
					} else {
						uni.showToast({
							title: '删除失败',
							icon: 'none'
						})
					}
				}
			});
		},
		tapPopup() {
			let Commonly = uni.getStorageSync('Commonly')
			this.Commonlylist.LUSERCODE = global.userinfo.lusercode
			uni.request({
				url: this.ip + '/api/addUserStaple', //仅为示例，并非真实接口地址。
				method: 'POST',
				dataType: 'json',
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'token': uni.getStorageSync('token')
				},
				data: this.Commonlylist,
				success: function(res) {
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						global.Commonly = true
					} else {
						uni.showToast({
							title: '添加失败',
							icon: 'none'
						})
					}
				}
			});
		}
	}
}
// 报表页面横竖屏混入
export const tableFixed = {
	data() {
		return {
			active: "横屏",
			imgclass: "myimgone",
		}
	},
	onUnload() {
		//#ifdef APP-PLUS
		plus.screen.lockOrientation('portrait-primary')
		//#endif
	},
	methods: {
		switchP() {
			if (this.active == '横屏') {
				this.active = '竖屏'
				this.imgclass = 'myimgtwo'
				uni.showLoading({
					title: '加载中'
				});
				setTimeout(() => {
					plus.screen.lockOrientation('landscape')

					uni.hideLoading();
				}, 1000)
			} else {
				this.active = '横屏'
				this.imgclass = 'myimgone'
				uni.showLoading({
					title: '加载中'
				});
				setTimeout(() => {
					plus.screen.lockOrientation('portrait')

					uni.hideLoading();
				}, 1000)
			}
		}
	}
}
